"/**\n"
" * ====================================================================\n"
" * About\n"
" * ====================================================================\n"
" * Sarissa is an ECMAScript library acting as a cross-browser wrapper for native XML APIs.\n"
" * The library supports Gecko based browsers like Mozilla and Firefox,\n"
" * Internet Explorer (5.5+ with MSXML3.0+), Konqueror, Safari and a little of Opera\n"
" * @version ${project.version}\n"
" * @author: Manos Batsis, mailto: mbatsis at users full stop sourceforge full stop net\n"
" * ====================================================================\n"
" * Licence\n"
" * ====================================================================\n"
" * Sarissa is free software distributed under the GNU GPL version 2 (see <a href=\"gpl.txt\">gpl.txt</a>) or higher, \n"
" * GNU LGPL version 2.1 (see <a href=\"lgpl.txt\">lgpl.txt</a>) or higher and Apache Software License 2.0 or higher \n"
" * (see <a href=\"asl.txt\">asl.txt</a>). This means you can choose one of the three and use that if you like. If \n"
" * you make modifications under the ASL, i would appreciate it if you submitted those.\n"
" * In case your copy of Sarissa does not include the license texts, you may find\n"
" * them online in various formats at <a href=\"http://www.gnu.org\">http://www.gnu.org</a> and \n"
" * <a href=\"http://www.apache.org\">http://www.apache.org</a>.\n"
" * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY \n"
" * KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE \n"
" * WARRANTIES OF MERCHANTABILITY,FITNESS FOR A PARTICULAR PURPOSE \n"
" * AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR \n"
" * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n"
" * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR \n"
" * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE \n"
" * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n"
" */\n"
"/**\n"
" * <p>Sarissa is a utility class. Provides \"static\" methods for DOMDocument, \n"
" * DOM Node serialization to XML strings and other utility goodies.</p>\n"
" * @constructor\n"
" */\n"
"function Sarissa(){};\n"
"Sarissa.VERSION = \"${project.version}\";\n"
"Sarissa.PARSED_OK = \"Document contains no parsing errors\";\n"
"Sarissa.PARSED_EMPTY = \"Document is empty\";\n"
"Sarissa.PARSED_UNKNOWN_ERROR = \"Not well-formed or other error\";\n"
"Sarissa.IS_ENABLED_TRANSFORM_NODE = false;\n"
"var _sarissa_iNsCounter = 0;\n"
"var _SARISSA_IEPREFIX4XSLPARAM = \"\";\n"
"var _SARISSA_HAS_DOM_IMPLEMENTATION = document.implementation && true;\n"
"var _SARISSA_HAS_DOM_CREATE_DOCUMENT = _SARISSA_HAS_DOM_IMPLEMENTATION && document.implementation.createDocument;\n"
"var _SARISSA_HAS_DOM_FEATURE = _SARISSA_HAS_DOM_IMPLEMENTATION && document.implementation.hasFeature;\n"
"var _SARISSA_IS_MOZ = _SARISSA_HAS_DOM_CREATE_DOCUMENT && _SARISSA_HAS_DOM_FEATURE;\n"
"var _SARISSA_IS_SAFARI = (navigator.userAgent && navigator.vendor && (navigator.userAgent.toLowerCase().indexOf(\"applewebkit\") != -1 || navigator.vendor.indexOf(\"Apple\") != -1));\n"
"var _SARISSA_IS_IE = document.all && window.ActiveXObject && navigator.userAgent.toLowerCase().indexOf(\"msie\") > -1  && navigator.userAgent.toLowerCase().indexOf(\"opera\") == -1;\n"
"if(!window.Node || !Node.ELEMENT_NODE){\n"
"    Node = {ELEMENT_NODE: 1, ATTRIBUTE_NODE: 2, TEXT_NODE: 3, CDATA_SECTION_NODE: 4, ENTITY_REFERENCE_NODE: 5,  ENTITY_NODE: 6, PROCESSING_INSTRUCTION_NODE: 7, COMMENT_NODE: 8, DOCUMENT_NODE: 9, DOCUMENT_TYPE_NODE: 10, DOCUMENT_FRAGMENT_NODE: 11, NOTATION_NODE: 12};\n"
"};\n"
"\n"
"if(typeof XMLDocument == \"undefined\" && typeof Document !=\"undefined\"){ XMLDocument = Document; } \n"
"\n"
"// IE initialization\n"
"if(_SARISSA_IS_IE){\n"
"    // for XSLT parameter names, prefix needed by IE\n"
"    _SARISSA_IEPREFIX4XSLPARAM = \"xsl:\";\n"
"    // used to store the most recent ProgID available out of the above\n"
"    var _SARISSA_DOM_PROGID = \"\";\n"
"    var _SARISSA_XMLHTTP_PROGID = \"\";\n"
"    var _SARISSA_DOM_XMLWRITER = \"\";\n"
"    /**\n"
"     * Called when the Sarissa_xx.js file is parsed, to pick most recent\n"
"     * ProgIDs for IE, then gets destroyed.\n"
"     * @private\n"
"     * @param idList an array of MSXML PROGIDs from which the most recent will be picked for a given object\n"
"     * @param enabledList an array of arrays where each array has two items; the index of the PROGID for which a certain feature is enabled\n"
"     */\n"
"    Sarissa.pickRecentProgID = function (idList){\n"
"        // found progID flag\n"
"        var bFound = false;\n"
"        for(var i=0; i < idList.length && !bFound; i++){\n"
"            try{\n"
"                var oDoc = new ActiveXObject(idList[i]);\n"
"                o2Store = idList[i];\n"
"                bFound = true;\n"
"            }catch (objException){\n"
"                // trap; try next progID\n"
"            };\n"
"        };\n"
"        if (!bFound) {\n"
"            throw \"Could not retreive a valid progID of Class: \" + idList[idList.length-1]+\". (original exception: \"+e+\")\";\n"
"        };\n"
"        idList = null;\n"
"        return o2Store;\n"
"    };\n"
"    // pick best available MSXML progIDs\n"
"    _SARISSA_DOM_PROGID = null;\n"
"    _SARISSA_THREADEDDOM_PROGID = null;\n"
"    _SARISSA_XSLTEMPLATE_PROGID = null;\n"
"    _SARISSA_XMLHTTP_PROGID = null;\n"
"    if(!window.XMLHttpRequest){\n"
"        /**\n"
"         * Emulate XMLHttpRequest\n"
"         * @constructor\n"
"         */\n"
"        XMLHttpRequest = function() {\n"
"            if(!_SARISSA_XMLHTTP_PROGID){\n"
"                _SARISSA_XMLHTTP_PROGID = Sarissa.pickRecentProgID([\"Msxml2.XMLHTTP.6.0\", \"MSXML2.XMLHTTP.3.0\", \"MSXML2.XMLHTTP\", \"Microsoft.XMLHTTP\"]);\n"
"            };\n"
"            return new ActiveXObject(_SARISSA_XMLHTTP_PROGID);\n"
"        };\n"
"    };\n"
"    // we dont need this anymore\n"
"    //============================================\n"
"    // Factory methods (IE)\n"
"    //============================================\n"
"    // see non-IE version\n"
"    Sarissa.getDomDocument = function(sUri, sName){\n"
"        if(!_SARISSA_DOM_PROGID){\n"
"            _SARISSA_DOM_PROGID = Sarissa.pickRecentProgID([\"Msxml2.DOMDocument.6.0\", \"Msxml2.DOMDocument.3.0\", \"MSXML2.DOMDocument\", \"MSXML.DOMDocument\", \"Microsoft.XMLDOM\"]);\n"
"        };\n"
"        var oDoc = new ActiveXObject(_SARISSA_DOM_PROGID);\n"
"        // if a root tag name was provided, we need to load it in the DOM object\n"
"        if (sName){\n"
"            // create an artifical namespace prefix \n"
"            // or reuse existing prefix if applicable\n"
"            var prefix = \"\";\n"
"            if(sUri){\n"
"                if(sName.indexOf(\":\") > 1){\n"
"                    prefix = sName.substring(0, sName.indexOf(\":\"));\n"
"                    sName = sName.substring(sName.indexOf(\":\")+1); \n"
"                }else{\n"
"                    prefix = \"a\" + (_sarissa_iNsCounter++);\n"
"                };\n"
"            };\n"
"            // use namespaces if a namespace URI exists\n"
"            if(sUri){\n"
"                oDoc.loadXML('<' + prefix+':'+sName + \" xmlns:\" + prefix + \"=\\\"\" + sUri + \"\\\"\" + \" />\");\n"
"            } else {\n"
"                oDoc.loadXML('<' + sName + \" />\");\n"
"            };\n"
"        };\n"
"        return oDoc;\n"
"    };\n"
"    // see non-IE version   \n"
"    Sarissa.getParseErrorText = function (oDoc) {\n"
"        var parseErrorText = Sarissa.PARSED_OK;\n"
"        if(oDoc && oDoc.parseError && oDoc.parseError.errorCode && oDoc.parseError.errorCode != 0){\n"
"            parseErrorText = \"XML Parsing Error: \" + oDoc.parseError.reason + \n"
"                \"\\nLocation: \" + oDoc.parseError.url + \n"
"                \"\\nLine Number \" + oDoc.parseError.line + \", Column \" + \n"
"                oDoc.parseError.linepos + \n"
"                \":\\n\" + oDoc.parseError.srcText +\n"
"                \"\\n\";\n"
"            for(var i = 0;  i < oDoc.parseError.linepos;i++){\n"
"                parseErrorText += \"-\";\n"
"            };\n"
"            parseErrorText +=  \"^\\n\";\n"
"        }\n"
"        else if(oDoc.documentElement == null){\n"
"            parseErrorText = Sarissa.PARSED_EMPTY;\n"
"        };\n"
"        return parseErrorText;\n"
"    };\n"
"    // see non-IE version\n"
"    Sarissa.setXpathNamespaces = function(oDoc, sNsSet) {\n"
"        oDoc.setProperty(\"SelectionLanguage\", \"XPath\");\n"
"        oDoc.setProperty(\"SelectionNamespaces\", sNsSet);\n"
"    };   \n"
"    /**\n"
"     * Basic implementation of Mozilla's XSLTProcessor for IE. \n"
"     * Reuses the same XSLT stylesheet for multiple transforms\n"
"     * @constructor\n"
"     */\n"
"    XSLTProcessor = function(){\n"
"        if(!_SARISSA_XSLTEMPLATE_PROGID){\n"
"            _SARISSA_XSLTEMPLATE_PROGID = Sarissa.pickRecentProgID([\"Msxml2.XSLTemplate.6.0\", \"MSXML2.XSLTemplate.3.0\"]);\n"
"        };\n"
"        this.template = new ActiveXObject(_SARISSA_XSLTEMPLATE_PROGID);\n"
"        this.processor = null;\n"
"    };\n"
"    /**\n"
"     * Imports the given XSLT DOM and compiles it to a reusable transform\n"
"     * <b>Note:</b> If the stylesheet was loaded from a URL and contains xsl:import or xsl:include elements,it will be reloaded to resolve those\n"
"     * @argument xslDoc The XSLT DOMDocument to import\n"
"     */\n"
"    XSLTProcessor.prototype.importStylesheet = function(xslDoc){\n"
"        if(!_SARISSA_THREADEDDOM_PROGID){\n"
"            _SARISSA_THREADEDDOM_PROGID = Sarissa.pickRecentProgID([\"MSXML2.FreeThreadedDOMDocument.6.0\", \"MSXML2.FreeThreadedDOMDocument.3.0\"]);\n"
"        };\n"
"        xslDoc.setProperty(\"SelectionLanguage\", \"XPath\");\n"
"        xslDoc.setProperty(\"SelectionNamespaces\", \"xmlns:xsl='http://www.w3.org/1999/XSL/Transform'\");\n"
"        // convert stylesheet to free threaded\n"
"        var converted = new ActiveXObject(_SARISSA_THREADEDDOM_PROGID);\n"
"        // make included/imported stylesheets work if exist and xsl was originally loaded from url\n"
"        if(xslDoc.url && xslDoc.selectSingleNode(\"//xsl:*[local-name() = 'import' or local-name() = 'include']\") != null){\n"
"            converted.async = false;\n"
"            if (_SARISSA_THREADEDDOM_PROGID == \"MSXML2.FreeThreadedDOMDocument.6.0\") { \n"
"                converted.setProperty(\"AllowDocumentFunction\", true); \n"
"                converted.resolveExternals = true; \n"
"            }\n"
"            converted.load(xslDoc.url);\n"
"        } else {\n"
"            converted.loadXML(xslDoc.xml);\n"
"        };\n"
"        converted.setProperty(\"SelectionNamespaces\", \"xmlns:xsl='http://www.w3.org/1999/XSL/Transform'\");\n"
"        var output = converted.selectSingleNode(\"//xsl:output\");\n"
"        this.outputMethod = output ? output.getAttribute(\"method\") : \"html\";\n"
"        this.template.stylesheet = converted;\n"
"        this.processor = this.template.createProcessor();\n"
"        // for getParameter and clearParameters\n"
"        this.paramsSet = new Array();\n"
"    };\n"
"\n"
"    /**\n"
"     * Transform the given XML DOM and return the transformation result as a new DOM document\n"
"     * @argument sourceDoc The XML DOMDocument to transform\n"
"     * @return The transformation result as a DOM Document\n"
"     */\n"
"    XSLTProcessor.prototype.transformToDocument = function(sourceDoc){\n"
"        // fix for bug 1549749\n"
"        if(_SARISSA_THREADEDDOM_PROGID){\n"
"            this.processor.input=sourceDoc;\n"
"            var outDoc=new ActiveXObject(_SARISSA_DOM_PROGID);\n"
"            this.processor.output=outDoc;\n"
"            this.processor.transform();\n"
"            return outDoc;\n"
"        }\n"
"        else{\n"
"            if(!_SARISSA_DOM_XMLWRITER){\n"
"                _SARISSA_DOM_XMLWRITER = Sarissa.pickRecentProgID([\"Msxml2.MXXMLWriter.6.0\", \"Msxml2.MXXMLWriter.3.0\", \"MSXML2.MXXMLWriter\", \"MSXML.MXXMLWriter\", \"Microsoft.XMLDOM\"]);\n"
"            };\n"
"            this.processor.input = sourceDoc;\n"
"            var outDoc = new ActiveXObject(_SARISSA_DOM_XMLWRITER);\n"
"            this.processor.output = outDoc; \n"
"            this.processor.transform();\n"
"            var oDoc = new ActiveXObject(_SARISSA_DOM_PROGID);\n"
"            oDoc.loadXML(outDoc.output+\"\");\n"
"            return oDoc;\n"
"        };\n"
"    };\n"
"    \n"
"    /**\n"
"     * Transform the given XML DOM and return the transformation result as a new DOM fragment.\n"
"     * <b>Note</b>: The xsl:output method must match the nature of the owner document (XML/HTML).\n"
"     * @argument sourceDoc The XML DOMDocument to transform\n"
"     * @argument ownerDoc The owner of the result fragment\n"
"     * @return The transformation result as a DOM Document\n"
"     */\n"
"    XSLTProcessor.prototype.transformToFragment = function (sourceDoc, ownerDoc) {\n"
"        this.processor.input = sourceDoc;\n"
"        this.processor.transform();\n"
"        var s = this.processor.output;\n"
"        var f = ownerDoc.createDocumentFragment();\n"
"        if (this.outputMethod == 'text') {\n"
"            f.appendChild(ownerDoc.createTextNode(s));\n"
"        } else if (ownerDoc.body && ownerDoc.body.innerHTML) {\n"
"            var container = ownerDoc.createElement('div');\n"
"            container.innerHTML = s;\n"
"            while (container.hasChildNodes()) {\n"
"                f.appendChild(container.firstChild);\n"
"            }\n"
"        }\n"
"        else {\n"
"            var oDoc = new ActiveXObject(_SARISSA_DOM_PROGID);\n"
"            if (s.substring(0, 5) == '<?xml') {\n"
"                s = s.substring(s.indexOf('?>') + 2);\n"
"            }\n"
"            var xml = ''.concat('<my>', s, '</my>');\n"
"            oDoc.loadXML(xml);\n"
"            var container = oDoc.documentElement;\n"
"            while (container.hasChildNodes()) {\n"
"                f.appendChild(container.firstChild);\n"
"            }\n"
"        }\n"
"        return f;\n"
"    };\n"
"    \n"
"    /**\n"
"     * Set global XSLT parameter of the imported stylesheet\n"
"     * @argument nsURI The parameter namespace URI\n"
"     * @argument name The parameter base name\n"
"     * @argument value The new parameter value\n"
"     */\n"
"    XSLTProcessor.prototype.setParameter = function(nsURI, name, value){\n"
"        // make value a zero length string if null to allow clearing\n"
"        value = value ? value : \"\";\n"
"        // nsURI is optional but cannot be null \n"
"        if(nsURI){\n"
"            this.processor.addParameter(name, value, nsURI);\n"
"        }else{\n"
"            this.processor.addParameter(name, value);\n"
"        };\n"
"        // update updated params for getParameter \n"
"        if(!this.paramsSet[\"\"+nsURI]){\n"
"            this.paramsSet[\"\"+nsURI] = new Array();\n"
"        };\n"
"        this.paramsSet[\"\"+nsURI][name] = value;\n"
"    };\n"
"    /**\n"
"     * Gets a parameter if previously set by setParameter. Returns null\n"
"     * otherwise\n"
"     * @argument name The parameter base name\n"
"     * @argument value The new parameter value\n"
"     * @return The parameter value if reviously set by setParameter, null otherwise\n"
"     */\n"
"    XSLTProcessor.prototype.getParameter = function(nsURI, name){\n"
"        nsURI = \"\" + nsURI;\n"
"        if(this.paramsSet[nsURI] && this.paramsSet[nsURI][name]){\n"
"            return this.paramsSet[nsURI][name];\n"
"        }else{\n"
"            return null;\n"
"        };\n"
"    };\n"
"    /**\n"
"     * Clear parameters (set them to default values as defined in the stylesheet itself)\n"
"     */\n"
"    XSLTProcessor.prototype.clearParameters = function(){\n"
"        for(var nsURI in this.paramsSet){\n"
"            for(var name in this.paramsSet[nsURI]){\n"
"                if(nsURI){\n"
"                    this.processor.addParameter(name, \"\", nsURI);\n"
"                }else{\n"
"                    this.processor.addParameter(name, \"\");\n"
"                };\n"
"            };\n"
"        };\n"
"        this.paramsSet = new Array();\n"
"    };\n"
"}else{ /* end IE initialization, try to deal with real browsers now ;-) */\n"
"    if(_SARISSA_HAS_DOM_CREATE_DOCUMENT){\n"
"        /**\n"
"         * <p>Ensures the document was loaded correctly, otherwise sets the\n"
"         * parseError to -1 to indicate something went wrong. Internal use</p>\n"
"         * @private\n"
"         */\n"
"        Sarissa.__handleLoad__ = function(oDoc){\n"
"            Sarissa.__setReadyState__(oDoc, 4);\n"
"        };\n"
"        /**\n"
"        * <p>Attached by an event handler to the load event. Internal use.</p>\n"
"        * @private\n"
"        */\n"
"        _sarissa_XMLDocument_onload = function(){\n"
"            Sarissa.__handleLoad__(this);\n"
"        };\n"
"        /**\n"
"         * <p>Sets the readyState property of the given DOM Document object.\n"
"         * Internal use.</p>\n"
"         * @private\n"
"         * @argument oDoc the DOM Document object to fire the\n"
"         *          readystatechange event\n"
"         * @argument iReadyState the number to change the readystate property to\n"
"         */\n"
"        Sarissa.__setReadyState__ = function(oDoc, iReadyState){\n"
"            oDoc.readyState = iReadyState;\n"
"            oDoc.readystate = iReadyState;\n"
"            if (oDoc.onreadystatechange != null && typeof oDoc.onreadystatechange == \"function\")\n"
"                oDoc.onreadystatechange();\n"
"        };\n"
"        Sarissa.getDomDocument = function(sUri, sName){\n"
"            var oDoc = document.implementation.createDocument(sUri?sUri:null, sName?sName:null, null);\n"
"            if(!oDoc.onreadystatechange){\n"
"            \n"
"                /**\n"
"                * <p>Emulate IE's onreadystatechange attribute</p>\n"
"                */\n"
"                oDoc.onreadystatechange = null;\n"
"            };\n"
"            if(!oDoc.readyState){\n"
"                /**\n"
"                * <p>Emulates IE's readyState property, which always gives an integer from 0 to 4:</p>\n"
"                * <ul><li>1 == LOADING,</li>\n"
"                * <li>2 == LOADED,</li>\n"
"                * <li>3 == INTERACTIVE,</li>\n"
"                * <li>4 == COMPLETED</li></ul>\n"
"                */\n"
"                oDoc.readyState = 0;\n"
"            };\n"
"            oDoc.addEventListener(\"load\", _sarissa_XMLDocument_onload, false);\n"
"            return oDoc;\n"
"        };\n"
"        if(window.XMLDocument){\n"
"            // do nothing\n"
"        }// TODO: check if the new document has content before trying to copynodes, check  for error handling in DOM 3 LS\n"
"        else if(_SARISSA_HAS_DOM_FEATURE && window.Document && !Document.prototype.load && document.implementation.hasFeature('LS', '3.0')){\n"
"            //Opera 9 may get the XPath branch which gives creates XMLDocument, therefore it doesn't reach here which is good\n"
"            /**\n"
"            * <p>Factory method to obtain a new DOM Document object</p>\n"
"            * @argument sUri the namespace of the root node (if any)\n"
"            * @argument sUri the local name of the root node (if any)\n"
"            * @returns a new DOM Document\n"
"            */\n"
"            Sarissa.getDomDocument = function(sUri, sName){\n"
"                var oDoc = document.implementation.createDocument(sUri?sUri:null, sName?sName:null, null);\n"
"                return oDoc;\n"
"            };\n"
"        }\n"
"        else {\n"
"            Sarissa.getDomDocument = function(sUri, sName){\n"
"                var oDoc = document.implementation.createDocument(sUri?sUri:null, sName?sName:null, null);\n"
"                // looks like safari does not create the root element for some unknown reason\n"
"                if(oDoc && (sUri || sName) && !oDoc.documentElement){\n"
"                    oDoc.appendChild(oDoc.createElementNS(sUri, sName));\n"
"                };\n"
"                return oDoc;\n"
"            };\n"
"        };\n"
"    };//if(_SARISSA_HAS_DOM_CREATE_DOCUMENT)\n"
"};\n"
"//==========================================\n"
"// Common stuff\n"
"//==========================================\n"
"if(!window.DOMParser){\n"
"    if(_SARISSA_IS_SAFARI){\n"
"        /*\n"
"         * DOMParser is a utility class, used to construct DOMDocuments from XML strings\n"
"         * @constructor\n"
"         */\n"
"        DOMParser = function() { };\n"
"        /** \n"
"        * Construct a new DOM Document from the given XMLstring\n"
"        * @param sXml the given XML string\n"
"        * @param contentType the content type of the document the given string represents (one of text/xml, application/xml, application/xhtml+xml). \n"
"        * @return a new DOM Document from the given XML string\n"
"        */\n"
"        DOMParser.prototype.parseFromString = function(sXml, contentType){\n"
"            var xmlhttp = new XMLHttpRequest();\n"
"            xmlhttp.open(\"GET\", \"data:text/xml;charset=utf-8,\" + encodeURIComponent(sXml), false);\n"
"            xmlhttp.send(null);\n"
"            return xmlhttp.responseXML;\n"
"        };\n"
"    }else if(Sarissa.getDomDocument && Sarissa.getDomDocument() && Sarissa.getDomDocument(null, \"bar\").xml){\n"
"        DOMParser = function() { };\n"
"        DOMParser.prototype.parseFromString = function(sXml, contentType){\n"
"            var doc = Sarissa.getDomDocument();\n"
"            doc.loadXML(sXml);\n"
"            return doc;\n"
"        };\n"
"    };\n"
"};\n"
"\n"
"if((typeof(document.importNode) == \"undefined\") && _SARISSA_IS_IE){\n"
"    try{\n"
"        /**\n"
"        * Implementation of importNode for the context window document in IE.\n"
"        * If <code>oNode</code> is a TextNode, <code>bChildren</code> is ignored.\n"
"        * @param oNode the Node to import\n"
"        * @param bChildren whether to include the children of oNode\n"
"        * @returns the imported node for further use\n"
"        */\n"
"        document.importNode = function(oNode, bChildren){\n"
"            var tmp;\n"
"            if (oNode.nodeName=='#text') {\n"
"                return document.createTextElement(oNode.data);\n"
"            }\n"
"            else {\n"
"                if(oNode.nodeName == \"tbody\" || oNode.nodeName == \"tr\"){\n"
"                    tmp = document.createElement(\"table\");\n"
"                }\n"
"                else if(oNode.nodeName == \"td\"){\n"
"                    tmp = document.createElement(\"tr\");\n"
"                }\n"
"                else if(oNode.nodeName == \"option\"){\n"
"                    tmp = document.createElement(\"select\");\n"
"                }\n"
"                else{\n"
"                    tmp = document.createElement(\"div\");\n"
"                };\n"
"                if(bChildren){\n"
"                    tmp.innerHTML = oNode.xml ? oNode.xml : oNode.outerHTML;\n"
"                }else{\n"
"                    tmp.innerHTML = oNode.xml ? oNode.cloneNode(false).xml : oNode.cloneNode(false).outerHTML;\n"
"                };\n"
"                return tmp.getElementsByTagName(\"*\")[0];\n"
"            };\n"
"            \n"
"        };\n"
"    }catch(e){ };\n"
"};\n"
"if(!Sarissa.getParseErrorText){\n"
"    /**\n"
"     * <p>Returns a human readable description of the parsing error. Usefull\n"
"     * for debugging. Tip: append the returned error string in a &lt;pre&gt;\n"
"     * element if you want to render it.</p>\n"
"     * <p>Many thanks to Christian Stocker for the initial patch.</p>\n"
"     * @argument oDoc The target DOM document\n"
"     * @returns The parsing error description of the target Document in\n"
"     *          human readable form (preformated text)\n"
"     */\n"
"    Sarissa.getParseErrorText = function (oDoc){\n"
"        var parseErrorText = Sarissa.PARSED_OK;\n"
"        if(!oDoc.documentElement){\n"
"            parseErrorText = Sarissa.PARSED_EMPTY;\n"
"        } else if(oDoc.documentElement.tagName == \"parsererror\"){\n"
"            parseErrorText = oDoc.documentElement.firstChild.data;\n"
"            parseErrorText += \"\\n\" +  oDoc.documentElement.firstChild.nextSibling.firstChild.data;\n"
"        } else if(oDoc.getElementsByTagName(\"parsererror\").length > 0){\n"
"            var parsererror = oDoc.getElementsByTagName(\"parsererror\")[0];\n"
"            parseErrorText = Sarissa.getText(parsererror, true)+\"\\n\";\n"
"        } else if(oDoc.parseError && oDoc.parseError.errorCode != 0){\n"
"            parseErrorText = Sarissa.PARSED_UNKNOWN_ERROR;\n"
"        };\n"
"        return parseErrorText;\n"
"    };\n"
"};\n"
"Sarissa.getText = function(oNode, deep){\n"
"    var s = \"\";\n"
"    var nodes = oNode.childNodes;\n"
"    for(var i=0; i < nodes.length; i++){\n"
"        var node = nodes[i];\n"
"        var nodeType = node.nodeType;\n"
"        if(nodeType == Node.TEXT_NODE || nodeType == Node.CDATA_SECTION_NODE){\n"
"            s += node.data;\n"
"        } else if(deep == true\n"
"                    && (nodeType == Node.ELEMENT_NODE\n"
"                        || nodeType == Node.DOCUMENT_NODE\n"
"                        || nodeType == Node.DOCUMENT_FRAGMENT_NODE)){\n"
"            s += Sarissa.getText(node, true);\n"
"        };\n"
"    };\n"
"    return s;\n"
"};\n"
"if(!window.XMLSerializer \n"
"    && Sarissa.getDomDocument \n"
"    && Sarissa.getDomDocument(\"\",\"foo\", null).xml){\n"
"    /**\n"
"     * Utility class to serialize DOM Node objects to XML strings\n"
"     * @constructor\n"
"     */\n"
"    XMLSerializer = function(){};\n"
"    /**\n"
"     * Serialize the given DOM Node to an XML string\n"
"     * @param oNode the DOM Node to serialize\n"
"     */\n"
"    XMLSerializer.prototype.serializeToString = function(oNode) {\n"
"        return oNode.xml;\n"
"    };\n"
"};\n"
"\n"
"/**\n"
" * strips tags from a markup string\n"
" */\n"
"Sarissa.stripTags = function (s) {\n"
"    return s.replace(/<[^>]+>/g,\"\");\n"
"};\n"
"/**\n"
" * <p>Deletes all child nodes of the given node</p>\n"
" * @argument oNode the Node to empty\n"
" */\n"
"Sarissa.clearChildNodes = function(oNode) {\n"
"    // need to check for firstChild due to opera 8 bug with hasChildNodes\n"
"    while(oNode.firstChild) {\n"
"        oNode.removeChild(oNode.firstChild);\n"
"    };\n"
"};\n"
"/**\n"
" * <p> Copies the childNodes of nodeFrom to nodeTo</p>\n"
" * <p> <b>Note:</b> The second object's original content is deleted before \n"
" * the copy operation, unless you supply a true third parameter</p>\n"
" * @argument nodeFrom the Node to copy the childNodes from\n"
" * @argument nodeTo the Node to copy the childNodes to\n"
" * @argument bPreserveExisting whether to preserve the original content of nodeTo, default is false\n"
" */\n"
"Sarissa.copyChildNodes = function(nodeFrom, nodeTo, bPreserveExisting) {\n"
"    if((!nodeFrom) || (!nodeTo)){\n"
"        throw \"Both source and destination nodes must be provided\";\n"
"    };\n"
"    if(!bPreserveExisting){\n"
"        Sarissa.clearChildNodes(nodeTo);\n"
"    };\n"
"    var ownerDoc = nodeTo.nodeType == Node.DOCUMENT_NODE ? nodeTo : nodeTo.ownerDocument;\n"
"    var nodes = nodeFrom.childNodes;\n"
"    if(typeof(ownerDoc.importNode) != \"undefined\")  {\n"
"        for(var i=0;i < nodes.length;i++) {\n"
"            nodeTo.appendChild(ownerDoc.importNode(nodes[i], true));\n"
"        };\n"
"    } else {\n"
"        for(var i=0;i < nodes.length;i++) {\n"
"            nodeTo.appendChild(nodes[i].cloneNode(true));\n"
"        };\n"
"    };\n"
"};\n"
"\n"
"/**\n"
" * <p> Moves the childNodes of nodeFrom to nodeTo</p>\n"
" * <p> <b>Note:</b> The second object's original content is deleted before \n"
" * the move operation, unless you supply a true third parameter</p>\n"
" * @argument nodeFrom the Node to copy the childNodes from\n"
" * @argument nodeTo the Node to copy the childNodes to\n"
" * @argument bPreserveExisting whether to preserve the original content of nodeTo, default is\n"
" */ \n"
"Sarissa.moveChildNodes = function(nodeFrom, nodeTo, bPreserveExisting) {\n"
"    if((!nodeFrom) || (!nodeTo)){\n"
"        throw \"Both source and destination nodes must be provided\";\n"
"    };\n"
"    if(!bPreserveExisting){\n"
"        Sarissa.clearChildNodes(nodeTo);\n"
"    };\n"
"    var nodes = nodeFrom.childNodes;\n"
"    // if within the same doc, just move, else copy and delete\n"
"    if(nodeFrom.ownerDocument == nodeTo.ownerDocument){\n"
"        while(nodeFrom.firstChild){\n"
"            nodeTo.appendChild(nodeFrom.firstChild);\n"
"        };\n"
"    } else {\n"
"        var ownerDoc = nodeTo.nodeType == Node.DOCUMENT_NODE ? nodeTo : nodeTo.ownerDocument;\n"
"        if(typeof(ownerDoc.importNode) != \"undefined\") {\n"
"           for(var i=0;i < nodes.length;i++) {\n"
"               nodeTo.appendChild(ownerDoc.importNode(nodes[i], true));\n"
"           };\n"
"        }else{\n"
"           for(var i=0;i < nodes.length;i++) {\n"
"               nodeTo.appendChild(nodes[i].cloneNode(true));\n"
"           };\n"
"        };\n"
"        Sarissa.clearChildNodes(nodeFrom);\n"
"    };\n"
"};\n"
"\n"
"/** \n"
" * <p>Serialize any object to an XML string. All properties are serialized using the property name\n"
" * as the XML element name. Array elements are rendered as <code>array-item</code> elements, \n"
" * using their index/key as the value of the <code>key</code> attribute.</p>\n"
" * @argument anyObject the object to serialize\n"
" * @argument objectName a name for that object\n"
" * @return the XML serializationj of the given object as a string\n"
" */\n"
"Sarissa.xmlize = function(anyObject, objectName, indentSpace){\n"
"    indentSpace = indentSpace?indentSpace:'';\n"
"    var s = indentSpace  + '<' + objectName + '>';\n"
"    var isLeaf = false;\n"
"    if(!(anyObject instanceof Object) || anyObject instanceof Number || anyObject instanceof String \n"
"        || anyObject instanceof Boolean || anyObject instanceof Date){\n"
"        s += Sarissa.escape(\"\"+anyObject);\n"
"        isLeaf = true;\n"
"    }else{\n"
"        s += \"\\n\";\n"
"        var itemKey = '';\n"
"        var isArrayItem = anyObject instanceof Array;\n"
"        for(var name in anyObject){\n"
"            s += Sarissa.xmlize(anyObject[name], (isArrayItem?\"array-item key=\\\"\"+name+\"\\\"\":name), indentSpace + \"   \");\n"
"        };\n"
"        s += indentSpace;\n"
"    };\n"
"    return s += (objectName.indexOf(' ')!=-1?\"</array-item>\\n\":\"</\" + objectName + \">\\n\");\n"
"};\n"
"\n"
"/** \n"
" * Escape the given string chacters that correspond to the five predefined XML entities\n"
" * @param sXml the string to escape\n"
" */\n"
"Sarissa.escape = function(sXml){\n"
"    return sXml.replace(/&/g, \"&amp;\")\n"
"        .replace(/</g, \"&lt;\")\n"
"        .replace(/>/g, \"&gt;\")\n"
"        .replace(/\"/g, \"&quot;\")\n"
"        .replace(/'/g, \"&apos;\");\n"
"};\n"
"\n"
"/** \n"
" * Unescape the given string. This turns the occurences of the predefined XML \n"
" * entities to become the characters they represent correspond to the five predefined XML entities\n"
" * @param sXml the string to unescape\n"
" */\n"
"Sarissa.unescape = function(sXml){\n"
"    return sXml.replace(/&apos;/g,\"'\")\n"
"        .replace(/&quot;/g,\"\\\"\")\n"
"        .replace(/&gt;/g,\">\")\n"
"        .replace(/&lt;/g,\"<\")\n"
"        .replace(/&amp;/g,\"&\");\n"
"};\n"
"//   EOF\n"
